#include<bits/stdc++.h>
using namespace std;
int d[100005],v[100005],a[100005],p[100005];
int main(){
	freopen("detect.in","r",stdin);
	freopen("detect.out","w",stdout);
    int t;
    cin >> t;
    int n,m,l,V;
    int cnt=0;
    for(int i = 1;i <= t;i++){
        cin >> n >> m >> l >> V;
        for(int i = 1;i <= n;i++){
            cin >> d[i] >> v[i] >> a[i];
            if(v[i]>V)cnt++;
        }
        for(int i = 1;i <= m;i++){
            cin >> p[i];
        }
    }
    cout << cnt << ' ';
    if(cnt == 0)cout << 0;
    else cout << m-1;
    return 0;
}
